﻿using System.Data;
using System.Data.SQLite;
using System.Text;
using Stock.DBUtility;
using Stock.Model;

namespace Stock.Dal
{
    /// <summary>
    /// 数据访问类:ParameterTbDal
    /// </summary>
    public partial class ParameterTbDal
    {
        public ParameterTbDal()
        { }

        #region Method

        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public ParameterTbEntity GetModel(int Parameter_Code)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select Parameter_Code,Parameter_Type,Parameter_Value,Parameter_Name,Parameter_Desc from ParameterTb ");
            strSql.Append(" where Parameter_Code=@Parameter_Code");
            SQLiteParameter[] parameters = {
					new SQLiteParameter("@Parameter_Code", DbType.Int32,4)
};
            parameters[0].Value = Parameter_Code;

            ParameterTbEntity model = new ParameterTbEntity();
            DataSet ds = DbHelperSQLite.Query(strSql.ToString(), parameters);
            if (ds.Tables[0].Rows.Count > 0)
            {
                if (ds.Tables[0].Rows[0]["Parameter_Code"] != null && ds.Tables[0].Rows[0]["Parameter_Code"].ToString() != "")
                {
                    model.Parameter_Code = int.Parse(ds.Tables[0].Rows[0]["Parameter_Code"].ToString());
                }
                if (ds.Tables[0].Rows[0]["Parameter_Type"] != null && ds.Tables[0].Rows[0]["Parameter_Type"].ToString() != "")
                {
                    model.Parameter_Type = ds.Tables[0].Rows[0]["Parameter_Type"].ToString();
                }
                if (ds.Tables[0].Rows[0]["Parameter_Value"] != null && ds.Tables[0].Rows[0]["Parameter_Value"].ToString() != "")
                {
                    model.Parameter_Value = ds.Tables[0].Rows[0]["Parameter_Value"].ToString();
                }
                if (ds.Tables[0].Rows[0]["Parameter_Name"] != null && ds.Tables[0].Rows[0]["Parameter_Name"].ToString() != "")
                {
                    model.Parameter_Name = ds.Tables[0].Rows[0]["Parameter_Name"].ToString();
                }
                if (ds.Tables[0].Rows[0]["Parameter_Desc"] != null && ds.Tables[0].Rows[0]["Parameter_Desc"].ToString() != "")
                {
                    model.Parameter_Desc = ds.Tables[0].Rows[0]["Parameter_Desc"].ToString();
                }
                return model;
            }
            else
            {
                return null;
            }
        }

        /// <summary>
        /// 获得数据列表
        /// </summary>
        public DataSet GetList(string strWhere)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select Parameter_Code,Parameter_Type,Parameter_Value,Parameter_Name,Parameter_Desc ");
            strSql.Append(" FROM ParameterTb ");
            if (strWhere.Trim() != "")
            {
                strSql.Append(" where " + strWhere);
            }
            return DbHelperSQLite.Query(strSql.ToString());
        }

        /*
        /// <summary>
        /// 分页获取数据列表
        /// </summary>
        public DataSet GetList(int PageSize,int PageIndex,string strWhere)
        {
            SQLiteParameter[] parameters = {
                    new SQLiteParameter("@tblName", DbType.VarChar, 255),
                    new SQLiteParameter("@fldName", DbType.VarChar, 255),
                    new SQLiteParameter("@PageSize", DbType.Int32),
                    new SQLiteParameter("@PageIndex", DbType.Int32),
                    new SQLiteParameter("@IsReCount", DbType.bit),
                    new SQLiteParameter("@OrderType", DbType.bit),
                    new SQLiteParameter("@strWhere", DbType.VarChar,1000),
                    };
            parameters[0].Value = "ParameterTb";
            parameters[1].Value = "Parameter_Code";
            parameters[2].Value = PageSize;
            parameters[3].Value = PageIndex;
            parameters[4].Value = 0;
            parameters[5].Value = 0;
            parameters[6].Value = strWhere;
            return DbHelperSQLite.RunProcedure("UP_GetRecordByPage",parameters,"ds");
        }*/

        #endregion Method
    }
}